package ru.nosport.matrixaria.modules.user.rexample.server;

import ru.nosport.matrixaria.modules.common.AppServerProcess;
import ru.nosport.matrixaria.core.MessageHandler;
import ru.nosport.matrixaria.core.MessageHandlerException;
import ru.nosport.matrixaria.core.MLogger;
import org.apache.commons.configuration.Configuration;

import java.util.logging.Level;

/**
 * User: Victor Fabrichenko
 * Date: 24.12.2008
 * Time: 14:26:05
 */
public class RemoteServerStubApp implements AppServerProcess, RemoteServer{

	private String remoteServerRefName;

	public RemoteServerStubApp(Configuration _conf){
		this.remoteServerRefName = _conf.getString("remoteServerRefName");
	}

	public boolean moduleStart() throws Exception {
		return true;
	}

	public boolean moduleStop() {
		return true;
	}

	public boolean isModuleRunning() {
		return true;
	}

	public String moduleStat() {
		return "RemoteServerStubApp stat";
	}

	public DataContainer getDataContainer(String _key) {
		DataContainer dc = null;
		try {
			dc = (DataContainer) MessageHandler.sendMessage(this.remoteServerRefName, "getDataContainer", new Object[]{_key});
		} catch (MessageHandlerException e) {
			MLogger.get(this).log(Level.SEVERE, e.getMessage());
		}
		return dc;
	}

	public DataContainer[] getDataContainerList(Integer _count){
		DataContainer[] dc = new DataContainer[0];
		try {
			dc = (DataContainer[]) MessageHandler.sendMessage(this.remoteServerRefName, "getDataContainerList", new Object[]{_count});
		} catch (MessageHandlerException e) {
			MLogger.get(this).log(Level.SEVERE, e.getMessage());
		}
		return dc;
	}
}
